<%--@elvariable id="order" type="com.serviceprovider.business.module.order.valueobjects.OrderVO"--%>
<%--@elvariable id="isAdmin" type="java.lang.Boolean"--%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp" %>

<head>
    <title><spring:message code="admin.editorder.title"/></title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <link rel="stylesheet" href="<c:url value="/css/styles.css"/>"/>
    <script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
    <script type="text/javascript">
        function showChangeStatusForm() {
            document.getElementById("orderStatusId").style.visibility = 'visible';
        }

        function saveOrderStatus() {
            var statusId = document.getElementById("orderStatusId").options[document
                    .getElementById("orderStatusId").selectedIndex].value;
            if (statusId == -1)
                return;
            location.href = 'updateStatus.htm?id=${order.id}&orderStatusId='
                    + statusId;
        }

        function saveAssignment() {
            var userID = document.getElementById("assignedUserId").options[document
                    .getElementById("assignedUserId").selectedIndex].value;
            if (userID == -1)
                return;
            location.href = 'updateAssignedUserId.htm?id=${order.id}&assignedUserId='
                    + userID;
        }
    </script>
</head>

<body>
<c:choose>

    <c:when test="${isAdmin}">
        <%@include file="../top_menu.jsp" %>
    </c:when>
    <c:otherwise>
        <%@include file="/WEB-INF/jsp/serviceprovider/top_menu.jsp" %>
    </c:otherwise>
</c:choose>
<form:form commandName="editOrderForm" action="order.htm">
<table width="100%">
    <tr>
        <td><c:if test="${isAdmin}">
            <c:import url="/WEB-INF/jsp/menu/view_orders_menu.jsp"/>
        </c:if></td>
    </tr>
    <tr>
        <td>
            <%@include file="/WEB-INF/jsp/include/messages.jsp" %>
            <br/>
        </td>
    </tr>
</table>
<table width=100%>
    <tr>
        <td class="pageHeading"><spring:message code="admin.editorder.label.orderdetails"/><br/>
        </td>
        <c:if test="${isAdmin}">
            <td class="pageHeading" align="right"><spring:message code="admin.editorder.label.assignthisorder"/> <select
                    id="assignedUserId">
                <c:forEach items="${userList.pageItems}" var="item" varStatus="i">
                    <c:choose>
                        <c:when test="${order.orderAssignedTo == item}">
                            <option value="${item.id}" selected>${item.email}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${item.id}">${item.email}</option>
                        </c:otherwise>

                    </c:choose>

                </c:forEach>
            </select> <input type="button"
                             class='ui-button ui-state-default ui-corner-all'
                             onclick=saveAssignment(); value="<spring:message code="admin.editorder.button.save" />"/>
            </td>
        </c:if>
    </tr>

</table>
<table width="100%">
    <tr valign="top">
        <td width="50%" valign="top">
            <table width="100%" class="formTable">

                <tr class="formHeader">
                    <td colspan="3"><spring:message code="admin.editorder.label.order"/></td>
                </tr>
                <tr>
                    <td width="150" valign="top"><spring:message code="admin.editorder.label.orderid"/>:</td>
                    <td>${order.id}</td>
                </tr>
                <tr>
                    <td width="150" valign="top"><spring:message code="admin.editorder.label.ordername"/>:</td>
                    <td>${order.name}</td>
                </tr>
                <tr>
                    <td><spring:message code="admin.editorder.label.providerbusinessname"/>:</td>
                    <td>${order.provider.businessName}</td>
                </tr>

                <tr>
                    <td><spring:message code="admin.editorder.label.orderdate"/>:</td>
                    <td><fmt:formatDate value="${order.createdDate}" pattern="dd/mm/yyyy HH:MM"/></td>
                </tr>
                <tr>
                    <td><spring:message code="admin.editorder.label.totalpayeeamount"/>:</td>
                    <td><fmt:formatNumber value="${order.totalPayeeAmount /100}"
                                          type="number" minFractionDigits="2"/></td>
                </tr>
                <tr>
                    <td><spring:message code="admin.editorder.label.shippingmode"/>:</td>
                    <td>${shippingList[order.mode].mode}</td>
                </tr>
                <tr>
                    <td><spring:message code="admin.editorder.label.shippingtips"/>:</td>
                    <td>${order.tips}</td>
                </tr>
                <tr>
                    <td><spring:message code="admin.editorder.label.shippinginstructions"/>:</td>
                    <td>${order.instructions}</td>
                </tr>

                <tr>
                    <td><spring:message code="admin.editorder.label.orderstatus"/>:</td>
                    <td>${order.orderStatus.name} <c:if test="${isAdmin}">
                        <a href="#" onclick=showChangeStatusForm();><spring:message
                                code="admin.editorder.label.change"/></a>
                        <select id="orderStatusId" style="visibility: hidden"
                                onchange="saveOrderStatus();">
                            <option value="-1"></option>
                            <c:forEach items="${orderStatusList}" var="item" varStatus="i">
                                <option value="${item.id}">${item.name}</option>
                            </c:forEach>
                        </select>
                    </c:if></td>
                </tr>
            </table>
        </td>
        <td>
            <table class="formTable" width=100%>
                <tr class="formHeader">
                    <td colspan="3"><spring:message code="admin.editorder.label.comments"/></td>
                </tr>
                <tr>
                    <td><c:choose>
                        <c:when test="${isAdmin}">
                            <div style="overflow: auto; height: 50px">
                                <c:forEach var="comment" items="${order.commentList}"
                                           varStatus="i">
                                    ${comment}<br/>
                                </c:forEach>
                            </div>
                        </c:when>
                        <c:otherwise>
                            <div style="overflow: auto; height: 120px">
                                <c:forEach var="comment" items="${order.commentList}"
                                           varStatus="i">
                                    ${comment}<br/>
                                </c:forEach>
                            </div>
                        </c:otherwise>
                    </c:choose></td>
                </tr>
                <tr>
                    <td><c:if test="${isAdmin}">

                        <table border=0 cellpadding=4 cellspacing=1 width=100%>


                            <tr>
                                <td><form:hidden path="savedOrderId"/> <form:textarea
                                        path="comment" rows="3" cols="40"/></td>
                                <td><input type="submit"
                                           class='ui-button ui-state-default ui-corner-all'
                                           value="<spring:message code="admin.editorder.button.save" />"
                                           style="height: 60px"/></td>
                            </tr>
                        </table>

                    </c:if>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>


<c:forEach var="batchVO" items="${order.batchList}">
    <table width=100% class="formTable" border=1>
        <tr class="formHeader">
            <td colspan="${batchVO.noOfPayees+7}"><spring:message code="admin.editorder.label.batchapprovedon"
                                                                  arguments="${batchVO.id}"/> <fmt:formatDate
                    value="${batchVO.batchDate}"
                    type="date" pattern="dd/mm/yyyy HH:MM"/></td>
        </tr>
        <tr>
            <td rowspan="3"><spring:message code="admin.editorder.label.ser"/></td>
            <td rowspan="3"><spring:message code="admin.editorder.label.ssn"/></td>
            <td rowspan="3"><spring:message code="admin.editorder.label.customername"/></td>
            <td rowspan="3"><spring:message code="admin.editorder.label.amountreceived"/></td>
            <td colspan="${batchVO.noOfPayees+2}" style="text-align: center;"><spring:message
                    code="admin.editorder.label.miscellanueouspayment"/></td>
            <th rowspan="3"><spring:message code="admin.editorder.label.customerbalance"/></th>
        </tr>
        <tr>
            <th rowspan="2"><spring:message code="admin.editorder.label.svcfee"/></th>
            <th rowspan="2"><spring:message code="admin.editorder.label.selffee"/></th>
            <c:if test="${batchVO.noOfPayees > 0}">
                <th colspan="${batchVO.noOfPayees}" style="text-align: center;"><spring:message
                        code="admin.editorder.label.payees"/></th>
            </c:if>
        </tr>
        <tr>
            <c:forEach var="entry" items="${batchVO.payeeMap}">
                <th>${entry.value}</th>
            </c:forEach>

                <%-- <th>${batchVO.payee1Name}</th>
                    <th>${batchVO.payee2Name}</th>
                    <th>${batchVO.payee3Name}</th>
                    <th>${batchVO.payee4Name}</th> --%>
        </tr>
        <tbody>
        <c:forEach var="transaction" items="${batchVO.transactions}"
                   varStatus="i">

            <tr>
                <td>${transaction.value.id}</td>
                <td>${transaction.value.customerSSN}</td>
                <td>${transaction.value.customerName}</td>
                <td><fmt:formatNumber value="${transaction.value.amount  /100}"
                                      type="number" minFractionDigits="2"/></td>
                <td><fmt:formatNumber value="${transaction.value.serviceFee /100}"
                                      type="number" minFractionDigits="2"/></td>
                <td><fmt:formatNumber value="${transaction.value.selfFee /100}"
                                      type="number" minFractionDigits="2"/></td>
                <c:forEach var="userAmount"
                           items="${transaction.value.amounts}">
                    <td><fmt:formatNumber value="${userAmount.value /100}"
                                          type="number" minFractionDigits="2"/></td>
                </c:forEach>
                    <%-- 	<td>${transaction.payee1Amount}</td>
                             <td>${transaction.payee2Amount}</td>
                             <td>${transaction.payee3Amount}</td>
                             <td>${transaction.payee4Amount}</td> --%>
                <td><fmt:formatNumber value="${transaction.value.customerBalance /100}"
                                      type="number" minFractionDigits="2"/></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</c:forEach>
</form:form>
<%@include file="/WEB-INF/jsp/include/footer.jsp" %>
</body>
</html>

